package com.zzty.txj1.dao;

import com.zzty.txj1.entity.DoEvent;
import com.zzty.txj1.entity.SearchDoEvent;
import com.zzty.txj1.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DoEventDao {
    @Select("select * from doevent where id=#{id}")
    DoEvent getDoEventById(DoEvent doEvent);

    @Insert("insert into doevent (userId, eventId, result, date, finalResult) values (#{userId}, #{eventId}, #{result}, #{date},null)")
    int initDoEvent(DoEvent doEvent);

    @Select("select * from doevent where userId=#{userId} and date=#{date};")
    List<DoEvent> checkEvents(DoEvent doEvent);

    @Update("update doevent set finalResult=1 where id=#{id}")
    Integer updateUserEvent(DoEvent doEvent);

    @Update("update doevent set finalResult=0 where id=#{id}")
    Integer updateUserEvent1(DoEvent doEvent);

    @Update("update doevent set result=1 where id=#{id}")
    Integer updateUserEvent2(DoEvent doEvent);

    @Select("select * from  doevent where userId=#{userId} and eventId=#{eventId} and date=#{date}")
    DoEvent getDoEvent(DoEvent doEvent);

    @Update("update doevent set finalResult=#{finalResult} where userId=#{userId} and date=#{date}")
    Integer updateDovent(DoEvent doEvent);

    @Update("update doevent set result=#{result} where userId=#{userId} and eventId=#{eventId} and date=#{date}")
    Integer updateDoEvent(DoEvent doEvent);

    @Update("update doevent set finalResult=#{finalResult} where userId=#{userId} and date=#{date} and eventId=#{eventId}")
    Integer updateDovent1(DoEvent doEvent);

    @Select("select * from  doevent where userId=#{userId} and date=#{date}")
    List<DoEvent> getDoEventByUserDate(DoEvent doEvent);

    @Select("select * from doevent where userId=#{userId} and date between #{bDate} and #{eDate}")
    List<DoEvent> getDoEventByDate(SearchDoEvent searchDoEvent);

    @Select("select * from doevent where userId=#{userId}")
    List<DoEvent> getDoeventByUserId(Integer userId);

    @Delete("delete from doevent where id=#{id}")
    Integer deleteDoEventById(DoEvent doEvent);

    @Select("SELECT * FROM doevent where DATE_SUB(CURDATE(), INTERVAL 7 DAY) < date(date) and userId=#{id}")
    List<DoEvent> getAWeekDoEventByUserId(User user);

    @Select("select count(*) from doevent where finalResult=1 and userId=#{userId} and eventId=#{eventId} and date between #{bDate} and #{eDate} ")
    Integer getNumsByUserIdAndEventId(SearchDoEvent searchDoEvent);
}
